package br.edu.ufcg.greengrid.event;

public class MachineIdToOperationsPerSecondEvent extends Event implements
		Comparable<MachineIdToOperationsPerSecondEvent> {

	private String machineId;

	private long operationsPerSecond;

	public MachineIdToOperationsPerSecondEvent(String machineId, long operationsPerSecond) {

		super();
		this.machineId = machineId;
		this.operationsPerSecond = operationsPerSecond;
	}

	public String getMachineId() {

		return machineId;
	}

	public long getOperationsPerSecond() {

		return operationsPerSecond;
	}

	@Override
	public int hashCode() {

		final int prime = 31;
		int result = 1;
		result = prime * result + ((machineId == null) ? 0 : machineId.hashCode());
		result = prime * result + (int) (operationsPerSecond ^ (operationsPerSecond >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {

		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MachineIdToOperationsPerSecondEvent other = (MachineIdToOperationsPerSecondEvent) obj;
		if (machineId == null) {
			if (other.machineId != null)
				return false;
		} else if (!machineId.equals(other.machineId))
			return false;
		if (operationsPerSecond != other.operationsPerSecond)
			return false;
		return true;
	}

	@Override
	public int compareTo(MachineIdToOperationsPerSecondEvent o) {

		if (this.machineId != o.machineId) {
			return this.machineId.compareTo(o.machineId);
		}

		if (this.operationsPerSecond != o.operationsPerSecond) {
			return this.operationsPerSecond - o.operationsPerSecond > 0 ? 1 : -1;
		}

		return 0;
	}

}
